<?php
/**
 * Created by PhpStorm.
 * User: lili
 * Date: 2018/12/30
 * Time: 18:57
 */

namespace app\index\controller;


use app\index\model\note;
 
use system\core\controller\Controller;
use system\core\route\Request;
use system\library\Cache;
use system\library\Cookie;
use system\library\Session;

class index  extends Controller
{
    /*public function index(){
//        $t = new test();
//        $res = $t->query(' select * from test ');
//        var_dump($res);
//        echo 'welcome to myframework';
//         $cache = Cache::getInstance();
//         $cache->set('name','lili' );
//           $this->assign('name','lili' );
//           $this->display();
        $this->redirect('?m=index&c=index&a=main');
    }*/
    
    
   /* public function main(){
        test();
        $t = new note();
        $res = $t->query(' select * from note ');
        var_dump($res);


        $this->assign('name',array('sex'=>['f'=>'ff']) );
        $this->assign('is',true );
        $this->assign('data',[
            'name' => 'lili',
            'sex' => ['男','女'],
            'height' => '165'
        ] );
        $this->display();
    }*/
    
    public function index(){
//        echo $this->request->getPath();
         
        $this->display();
    }
    
    
    /*
     * 订单提交
     * 
     * */
    public function note(){


   

        $input = $this->request->input('','post');

        if (empty($input['name'])){
           $this->back('缺少name');
        }
        if (empty($input['email'])){
            $this->back('缺少email');
        }
        if (empty($input['phone'])){
            $this->back('缺少phone');
        }
        if (empty($input['note'])){
            $this->back('缺少note');
        }
        
        
        $notemodel = new note();
        $res = $notemodel->setNote($input['name'],$input['email'] ,$input['phone'] , $input['note']);
//        dump($notemodel->lastInsertId());
        if ($res !== false){
            $this->redirect('?m=index&c=index&a=main&id='.$notemodel->lastInsertId());
        }else{
            $this->back("提交失败");
        }
    }

    /*
     * 查看数据
     * 
     * */
    public function main(){
        $input = $this->request->input('','get');
        if (empty($input['id'])){
            echo "没有数据" ;
        }else{
            $id =$input['id'];
            $notemodel = new note();
            $res = $notemodel->getOne($id);
            if ($res!==false){
                $this->assign('note',$res );
            }
            $this->display();
        }



    }
    
    
    
}